function containsDuplicate2(nums: number[]): boolean {
   const oldLength = nums.length;
   const newLength = [...new Set(nums)].length
   if(oldLength !== newLength) return true;
   else return false;
};

// 通过set去重之后来判断新旧数组的长度

function containsDuplicate(nums: number[]): boolean {
    const oldLength = nums.length;
    const newMap = new Map<number, number>();
    nums.forEach((item: number) => {
        newMap.set(item,item)
    })
    const newLength = [...newMap].length;
    if(oldLength !== newLength) return true;
   else return false;
 };

//  map也一样

// map set 原理



const arr1 = [1,2,3,1]
console.log(containsDuplicate(arr1))